#!/usr/bin/bash

command="screen -dm  -S api -s /root/node_state_server.py"

install(){
    echo "#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
${command}
exit 0">/etc/rc.local
}

changeFile(){
    if grep -q "${command}" /etc/rc.local; then
        echo 'the script is installed yet.'
        exit 0
    fi

    if ! grep -q "exit 0" /etc/rc.local; then
        echo "${command}">>/etc/rc.local
    else:
        sudo sed -i '/^exit 0/i your_command' /etc/rc.local
    fi
    chmod +x  /etc/rc.local
}

if [ -f "/etc/rc.local" ]
then
    changeFile
else
	install
fi

